﻿using Efcore_Test.Data;
using Efcore_Test.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Distributed;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;

namespace Efcore_Test.Repositorys
{
    /// <summary>
    /// 仓储”((Repository)
    ///     仓储负责按照要求从数据库中读取数据以及把领域服务（三层架构中的领域服务）修改的数据保存回数据库。
    /// </summary>
    [Dependency(ServiceLifetime.Transient)]
    public class ArticleRepository : EfCoreRepository<Efcore_TestDbContext, Article, long>, IArticleRepository
    {
        /// <summary>
        /// 默认存储在MemoryDistributedCache Microsoft.Extensions.Caching.Memory
        /// 缓存在本地应用进程内的内存中
        /// </summary>
        public IDistributedCache distributedCache { get; set; }


        public ArticleRepository(IDbContextProvider<Efcore_TestDbContext> dbContextProvider) : base(dbContextProvider)
        {

        }

        public override Task<Article?> FindAsync(long id, bool includeDetails = true, CancellationToken cancellationToken = default)
        {
            return base.FindAsync(id, includeDetails, cancellationToken);
        }
    }
}
